package com.yf.system.modules.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yf.base.api.api.ApiRest;
import com.yf.base.api.api.controller.BaseController;
import com.yf.base.api.api.dto.PagingReqDTO;
import com.yf.system.modules.user.dto.SysUserBindDTO;
import com.yf.system.modules.user.dto.request.MobileLoginReqDTO;
import com.yf.system.modules.user.service.SysUserBindService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* <p>
* 登录绑定控制器
* </p>
*
* @author 聪明笨狗
* @since 2021-08-02 14:49
*/
@Api(tags={"登录绑定"})
@RestController
@RequestMapping("/api/sys/user/bind")
public class SysUserBindController extends BaseController {

    @Autowired
    private SysUserBindService baseService;

    /**
    * 绑定手机
    * @param reqDTO
    * @return
    */
    @ApiOperation(value = "绑定手机")
    @PostMapping("/bind-mobile")
    public ApiRest bindMobile(@RequestBody MobileLoginReqDTO reqDTO) {
        baseService.bindMobile(reqDTO, true);
        return super.success();
    }

    /**
     * 解绑手机
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "解绑手机")
    @PostMapping("/unbind-mobile")
    public ApiRest unBindMobile(@RequestBody MobileLoginReqDTO reqDTO) {
        baseService.unBindMobile(reqDTO, true);
        return super.success();
    }



    /**
     * 绑定手机
     * @param reqDTO
     * @return
     */
    @RequiresPermissions(value = {"sys:user:add", "sys:user:update"}, logical = Logical.OR)
    @ApiOperation(value = "绑定手机-管理端")
    @PostMapping("/direct-bind")
    public ApiRest directBind(@RequestBody MobileLoginReqDTO reqDTO) {
        baseService.bindMobile(reqDTO, false);
        return super.success();
    }

    /**
     * 解绑手机
     * @param reqDTO
     * @return
     */
    @RequiresPermissions(value = {"sys:user:add", "sys:user:update"}, logical = Logical.OR)
    @ApiOperation(value = "解绑手机-管理端")
    @PostMapping("/direct-unbind")
    public ApiRest directUnBind(@RequestBody MobileLoginReqDTO reqDTO) {
        baseService.unBindMobile(reqDTO, false);
        return super.success();
    }

    /**
    * 绑定列表
    * @param reqDTO
    * @return
    */
    @ApiOperation(value = "绑定列表")
    @PostMapping("/paging")
    public ApiRest<IPage<SysUserBindDTO>> paging(@RequestBody PagingReqDTO<SysUserBindDTO> reqDTO) {

        //分页查询并转换
        IPage<SysUserBindDTO> page = baseService.paging(reqDTO);

        return super.success(page);
    }

    /**
     * 绑定列表
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "绑定列表", notes = "前端查询绑定列表")
    @PostMapping("/bind-list")
    public ApiRest<IPage<SysUserBindDTO>> bindList(@RequestBody PagingReqDTO<SysUserBindDTO> reqDTO) {

        //分页查询并转换
        IPage<SysUserBindDTO> page = baseService.paging(reqDTO);

        return super.success(page);
    }


    /**
     * 查找用户绑定信息
     * @return
     */
    @RequiresPermissions(value = {"sys:user:add", "sys:user:update"}, logical = Logical.OR)
    @ApiOperation(value = "查找绑定信息")
    @PostMapping("/bind-info")
    public ApiRest<SysUserBindDTO> bindInfo(@RequestBody SysUserBindDTO reqDTO) {
        SysUserBindDTO bind = baseService.bindInfo(reqDTO);
        return success(bind);
    }
}
